package org.groupg.practice.jidesoft;

import com.jidesoft.swing.RangeSlider;

import javax.swing.*;
import java.awt.*;

public class RangeSliderExample {
    public static void main(String[] args) {
        JFrame frame = new JFrame("范围滑块示例");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 150);
        frame.setLayout(new FlowLayout());

        // 创建范围滑块

        RangeSlider rangeSlider = new RangeSlider(0, 100);
        rangeSlider.setLowValue(20);
        rangeSlider.setHighValue(80);
        rangeSlider.setPreferredSize(new Dimension(350, 60));

        // 添加标签显示值
        JLabel label = new JLabel("当前范围: 20 - 80");

        // 添加监听器
        rangeSlider.addPropertyChangeListener(RangeSlider.PROPERTY_LOW_VALUE, evt -> {
            label.setText("当前范围: " + rangeSlider.getLowValue() + " - " + rangeSlider.getHighValue());
        });
        rangeSlider.addPropertyChangeListener(RangeSlider.PROPERTY_HIGH_VALUE, evt -> {
            label.setText("当前范围: " + rangeSlider.getLowValue() + " - " + rangeSlider.getHighValue());
        });

        frame.add(rangeSlider);
        frame.add(label);
        frame.setVisible(true);
    }
}